package com.css.project.oa.phoneMenu.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.css.framework.aspectj.lang.annotation.Log;
import com.css.framework.aspectj.lang.enums.BusinessType;
import com.css.project.oa.phoneMenu.domain.ProPhoneMenu;
import com.css.project.oa.phoneMenu.service.IProPhoneMenuService;
import com.css.project.oa.phoneMenu.vo.PhoneMenuVo;
import com.css.framework.web.controller.BaseController;
import com.css.framework.web.domain.AjaxResult;
import com.css.common.utils.poi.ExcelUtil;

/**
 * 手机菜单管理Controller
 * 
 * @author css
 * @date 2020-06-12
 */
@RestController
@RequestMapping("/phoneMenu/menu")
public class ProPhoneMenuController extends BaseController
{
    @Autowired
    private IProPhoneMenuService proPhoneMenuService;

    /**
     * 查询手机菜单管理列表
     */
    
    /*@GetMapping("/list")
    public TableDataInfo list(ProPhoneMenu proPhoneMenu)
    {
        startPage();
        List<ProPhoneMenu> list = proPhoneMenuService.selectProPhoneMenuList(proPhoneMenu);
        return getDataTable(list);
    }*/
    @PreAuthorize("@ss.hasPermi('phoneMenu:menu:list')")
    @GetMapping("/list")
    public AjaxResult list(ProPhoneMenu proPhoneMenu)
    {
    	List<ProPhoneMenu> list = proPhoneMenuService.selectProPhoneMenuList(proPhoneMenu);
        return AjaxResult.success(list);
    }
    /**
     * 导出手机菜单管理列表
     */
    @PreAuthorize("@ss.hasPermi('phoneMenu:menu:export')")
    @Log(title = "手机菜单管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ProPhoneMenu proPhoneMenu)
    {
        List<ProPhoneMenu> list = proPhoneMenuService.selectProPhoneMenuList(proPhoneMenu);
        ExcelUtil<ProPhoneMenu> util = new ExcelUtil<ProPhoneMenu>(ProPhoneMenu.class);
        return util.exportExcel(list, "menu");
    }

    /**
     * 获取手机菜单管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('phoneMenu:menu:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(proPhoneMenuService.selectProPhoneMenuById(id));
    }

    /**
     * 新增手机菜单管理
     */
    @PreAuthorize("@ss.hasPermi('phoneMenu:menu:add')")
    @Log(title = "手机菜单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProPhoneMenu proPhoneMenu)
    {
        return toAjax(proPhoneMenuService.insertProPhoneMenu(proPhoneMenu));
    }

    /**
     * 修改手机菜单管理
     */
    @PreAuthorize("@ss.hasPermi('phoneMenu:menu:edit')")
    @Log(title = "手机菜单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProPhoneMenu proPhoneMenu)
    {
        return toAjax(proPhoneMenuService.updateProPhoneMenu(proPhoneMenu));
    }

    /**
     * 删除手机菜单管理
     */
    @PreAuthorize("@ss.hasPermi('phoneMenu:menu:remove')")
    @Log(title = "手机菜单管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
    	int returnCode = proPhoneMenuService.deleteProPhoneMenuByIds(ids);
    	if(returnCode==-1) {
    		return AjaxResult.success("child");
    	}
        return toAjax(returnCode);
    }
    
    @GetMapping("/getMainMenuList")
    public AjaxResult getMainMenuList()
    {
        List<ProPhoneMenu> menus = proPhoneMenuService.getMainPhoneMenu();
        return AjaxResult.success(menus);
    }
    
    
}
